﻿using LJ.Abstractions.Extensions;
using LJ.WebApi.Mvc.DynamicWebApi;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJ.WebApi.UnifyResult.Mvc;

public class UnifyResultConfigureAction : IConfigureAction
{
    public void Configure(ActionModel action)
    {
        // 获取真实类型
        var returnType = action.ActionMethod.GetRealReturnType();
        if (returnType == typeof(void)) return;
        if (returnType == typeof(Task)) return;
        // 添加规范化结果特性
        action.Filters.Add(new ProducesResponseTypeAttribute(returnType, StatusCodes.Status200OK));
    }
}
